package com.zwr.sheller.shop.controller;

import com.zwr.sheller.core.common.JsonResult;
import com.zwr.sheller.core.common.LJCBusinessException;
import com.zwr.sheller.shop.service.GoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author ljc
 * @date 2022/1/6
 **/
@CrossOrigin
@RestController
@RequestMapping("/goods")
@Api(tags = "商品管理接口")
public class GoodsController {

    @Autowired
    GoodsService goodsService;

    @PostMapping("/selectGoodsWithPage")
    @ApiOperation(value = "搜索商品(带分页)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "itemId", value = "商品分类编号", dataType = "Long"),
            @ApiImplicitParam(name = "goodsNameOrKeyWord", value = "商品名称或关键词", dataType = "String"),
            @ApiImplicitParam(name = "rank", value = "分类级别", dataType = "Integer"),
            @ApiImplicitParam(name = "goodsLabel", value = "商品标签", dataType = "String"),
            @ApiImplicitParam(name = "page", value = "页码", dataType = "Integer"),
            @ApiImplicitParam(name = "size", value = "条数", dataType = "Integer")
    })
    public Map selectGoodsWithPage(Long itemId, String goodsNameOrKeyWord, Integer rank, String goodsLabel, Integer page, Integer size){
        return goodsService.selectGoodsWithPage(itemId, goodsNameOrKeyWord, rank, goodsLabel, page, size);
    }

    @PostMapping("/selectGoodsNoPage")
    @ApiOperation(value = "搜索商品(不带分页)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "itemId", value = "商品分类编号", dataType = "Long"),
            @ApiImplicitParam(name = "goodsNameOrKeyWord", value = "商品名称或关键词", dataType = "String"),
            @ApiImplicitParam(name = "rank", value = "分类级别", dataType = "Integer")
    })
    public Map selectGoodsNoPage(Long itemId, String goodsNameOrKeyWord, Integer rank){
        List<Map<String, Object>> list = goodsService.selectGoodsNoPage(itemId, goodsNameOrKeyWord, rank, "");
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setField("data", list);
        return jsonResult.getMap();
    }

    @PostMapping("/getGoodsClassification")
    @ApiOperation(value = "获取商品分类(添加商品基本信息时)")
    public Map getGoodsClassification(){
        return goodsService.getGoodsClassification();
    }

    @PostMapping("/getGoodsAllClassification")
    @ApiOperation(value = "获取商品所有分类")
    public Map getGoodsAllClassification(){
        return goodsService.getGoodsAllClassification();
    }

    @PostMapping("/addGoodsInfo")
    @ApiOperation(value = "添加商品信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "goods", value = "商品对象"),
            @ApiImplicitParam(name = "goodsSort", value = "商品排序", dataType = "Long"),
            @ApiImplicitParam(name = "goodsName", value = "商品名称", dataType = "String"),
            @ApiImplicitParam(name = "goodsTitle", value = "商品标题", dataType = "String"),
            @ApiImplicitParam(name = "goodsKeyWord", value = "关键词", dataType = "String"),
            @ApiImplicitParam(name = "goodsFirstItemId", value = "商品一级分类编号", dataType = "Integer"),
            @ApiImplicitParam(name = "goodsSecondItemId", value = "商品二级分类编号", dataType = "Integer"),
            @ApiImplicitParam(name = "goodsThirdItemId", value = "商品三级分类编号", dataType = "Integer"),
            @ApiImplicitParam(name = "goodsUnit", value = "商品计量单位", dataType = "String"),
            @ApiImplicitParam(name = "goodsLabel1", value = "商品标签一(推荐)", dataType = "String"),
            @ApiImplicitParam(name = "goodsLabel2", value = "商品标签一(新品)", dataType = "String"),
            @ApiImplicitParam(name = "goodsLabel3", value = "商品标签二(热卖)", dataType = "String"),
            @ApiImplicitParam(name = "goodsLabelGroupId", value = "商品自定义标签组", dataType = "Long"),
            @ApiImplicitParam(name = "goodsMainImg", value = "商品主图", dataType = "String"),
            @ApiImplicitParam(name = "goodsVirtualSale", value = "商品虚拟销量", dataType = "Long"),
            @ApiImplicitParam(name = "goodsDeliver", value = "商家配送范围", dataType = "Double"),
            @ApiImplicitParam(name = "goodsIsOnShelf", value = "是否上架", dataType = "Integer"),
            @ApiImplicitParam(name = "goodsGoodsBarCode", value = "商品条码", dataType = "Long"),
            @ApiImplicitParam(name = "goodsWarnStock", value = "商品预警库存", dataType = "Long"),
            @ApiImplicitParam(name = "goodsDesc", value = "商品详情描述", dataType = "String"),
            @ApiImplicitParam(name = "goodsIsRecommend", value = "商品是否启用掌柜推荐", dataType = "Boolean"),
            @ApiImplicitParam(name = "startPrice", value = "起批价对象"),
            @ApiImplicitParam(name = "num", value = "几个起(数组)", dataType = "Long"),
            @ApiImplicitParam(name = "onePrice", value = "每个多少钱(数组)", dataType = "Double"),
            @ApiImplicitParam(name = "originalPrice", value = "原价(数组)", dataType = "Double"),
            @ApiImplicitParam(name = "featureImg", value = "特色图对象(数组)"),
            @ApiImplicitParam(name = "sku", value = "sku对象"),
            @ApiImplicitParam(name = "specificationName", value = "规格", dataType = "String"),
            @ApiImplicitParam(name = "skuName", value = "sku名(数组)", dataType = "String"),
            @ApiImplicitParam(name = "skuStock", value = "sku库存(数组)", dataType = "Long"),
            @ApiImplicitParam(name = "skuPrice", value = "sku单价(数组)", dataType = "Double"),
            @ApiImplicitParam(name = "skuUnit", value = "sku单位(数组)", dataType = "String"),
            @ApiImplicitParam(name = "skuNum", value = "sku数量(数组)", dataType = "Long"),
            @ApiImplicitParam(name = "skuWeight", value = "sku重量(数组)", dataType = "Double"),
            @ApiImplicitParam(name = "param", value = "参数对象"),
            @ApiImplicitParam(name = "paramName", value = "参数名(数组)", dataType = "String"),
            @ApiImplicitParam(name = "value", value = "参数值(数组)", dataType = "String"),
            @ApiImplicitParam(name = "goodsDetailImg", value = "商品详情图对象(图片地址数组)"),
            @ApiImplicitParam(name = "marketing", value = "营销对象"),
            @ApiImplicitParam(name = "marketingDiscountByMoney", value = "满多少元", dataType = "Double"),
            @ApiImplicitParam(name = "marketingDiscountMoney", value = "享受多少折", dataType = "Double"),
            @ApiImplicitParam(name = "marketingDecreaseByMoney", value = "满多少元", dataType = "Double"),
            @ApiImplicitParam(name = "marketingDecreaseMoney", value = "减多少元", dataType = "Double"),
            @ApiImplicitParam(name = "marketingDiscountByCount", value = "满多少件", dataType = "Long"),
            @ApiImplicitParam(name = "marketingDiscountCount", value = "享受多少折", dataType = "Double"),
            @ApiImplicitParam(name = "marketingDecreaseByCount", value = "满多少件", dataType = "Long"),
            @ApiImplicitParam(name = "marketingDecreaseCount", value = "减多少元", dataType = "Double"),
            @ApiImplicitParam(name = "associateGoods", value = "关联对象(商品编号数组)"),
    })
    public Map addGoodsInfo(@RequestBody Map<String, Object> map) throws LJCBusinessException {
        return goodsService.addGoodsInfo(map);
    }

    @PostMapping("/getGoodsInfo")
    @ApiOperation(value = "获取商品信息")
    @ApiImplicitParam(name = "goodsId", value = "商品编号", dataType = "String")
    public Map getGoodsInfo(String goodsId){
        return goodsService.getGoodsInfo(goodsId);
    }

    @PostMapping("/editGoodsBasicInfo")
    @ApiOperation(value = "编辑商品基本信息")
    public Map editGoodsBasicInfo(@RequestBody Map<String, Object> map) throws LJCBusinessException {
        return goodsService.editGoodsBasicInfo(map);
    }

    @PostMapping("/editGoodsStock")
    @ApiOperation(value = "编辑商品库存")
    public Map editGoodsStock(@RequestBody Map<String, Object> map) {
        return goodsService.editGoodsStock(map);
    }

    @PostMapping("/editGoodsSpecification")
    @ApiOperation(value = "编辑商品规格")
    public Map editGoodsSpecification(@RequestBody Map<String, Object> map) {
        return goodsService.editGoodsSpecification(map);
    }

    @PostMapping("/editGoodsParameters")
    @ApiOperation(value = "编辑商品参数")
    public Map editGoodsParameters(@RequestBody Map<String, Object> map){
        return goodsService.editGoodsParameters(map);
    }

    @PostMapping("/editGoodsDetail")
    @ApiOperation(value = "编辑商品详情")
    public Map editGoodsDetail(@RequestBody Map<String, Object> map) throws LJCBusinessException {
        return goodsService.editGoodsDetail(map);
    }

    @PostMapping("/editGoodsMarketing")
    @ApiOperation(value = "编辑商品营销")
    public Map editGoodsMarketing(@RequestBody Map<String, Object> map){
        return goodsService.editGoodsMarketing(map);
    }

    @PostMapping("/editGoodsRecommend")
    @ApiOperation(value = "编辑商品掌柜推荐")
    public Map editGoodsRecommend(@RequestBody Map<String, Object> map){
        return goodsService.editGoodsRecommend(map);
    }

    @PostMapping("/deleteGoods")
    @ApiOperation(value = "删除商品")
    @ApiImplicitParam(name = "goodsId", value = "商品编号(数组)", dataType = "String")
    public Map deleteGoods(@RequestBody Map<String, Object> map) throws LJCBusinessException {
        return goodsService.deleteGoods(map);
    }

    @PostMapping("/downShelfGoods")
    @ApiOperation(value = "下架商品")
    @ApiImplicitParam(name = "goodsId", value = "商品编号(数组)", dataType = "String")
    public Map downShelfGoods(@RequestBody Map<String, Object> map){
        return goodsService.downShelfGoods(map);
    }

    @PostMapping("/upShelfGoods")
    @ApiOperation(value = "上架(审核)商品")
    @ApiImplicitParam(name = "goodsId", value = "商品编号(数组)", dataType = "String")
    public Map upShelfGoods(@RequestBody Map<String, Object> map){
        return goodsService.upShelfGoods(map);
    }

    @PostMapping("/getThirdClassification")
    @ApiOperation(value = "获取商品3级分类(修改分类时)")
    public Map getThirdClassification(){
        return goodsService.getThirdClassification();
    }

    @PostMapping("/updateGoodsClassification")
    @ApiOperation(value = "修改商品分类")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "goodsId", value = "商品编号数组", dataType = "String"),
            @ApiImplicitParam(name = "firstItemId", value = "商品一级分类编号", dataType = "Long"),
            @ApiImplicitParam(name = "secondItemId", value = "商品二级分类编号", dataType = "Long"),
            @ApiImplicitParam(name = "thirdItemId", value = "商品三级分类编号", dataType = "Long")
    })
    public Map updateGoodsClassification(@RequestBody Map<String, Object> map){
        return goodsService.updateGoodsClassification(map);
    }

    @PostMapping("/updateGoodsLabel")
    @ApiOperation(value = "修改商品标签(一个商品只能有一个标签组)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "goodsId", value = "商品编号(数组)", dataType = "String"),
            @ApiImplicitParam(name = "label1", value = "商品标签1(有就传入字符串，没有就传空字符串)", dataType = "String"),
            @ApiImplicitParam(name = "label2", value = "商品标签2(有就传入字符串，没有就传空字符串)", dataType = "String"),
            @ApiImplicitParam(name = "label3", value = "商品标签3(有就传入字符串，没有就传空字符串)", dataType = "String"),
            @ApiImplicitParam(name = "labelGroupId", value = "商品标签组编号", dataType = "Long")
    })
    public Map updateGoodsLabel(@RequestBody Map<String, Object> map){
        return goodsService.updateGoodsLabel(map);
    }

    @PostMapping("/getParentClassification")
    @ApiOperation(value = "获取上级分类")
    public Map getParentClassification(){
        return goodsService.getParentClassification();
    }

    @PostMapping("/addClassification")
    @ApiOperation(value = "添加商品分类")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sort", value = "分类排序", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "parentClassification", value = "上级分类", required = true, dataType = "String"),
            @ApiImplicitParam(name = "name", value = "分类名称", required = true, dataType = "String"),
            @ApiImplicitParam(name = "keyWord", value = "关键词", dataType = "String"),
            @ApiImplicitParam(name = "imgPath", value = "图标路径", dataType = "String"),
            @ApiImplicitParam(name = "isRelevance", value = "是否关联平台分类", required = true, dataType = "Boolean"),
            @ApiImplicitParam(name = "isDisplay", value = "是否显示", required = true, dataType = "Boolean"),
            @ApiImplicitParam(name = "isRecommend", value = "是否店铺首页推荐", required = true, dataType = "Boolean"),
            @ApiImplicitParam(name = "desc", value = "分类描述", dataType = "String")
    })
    public Map addClassification(Long sort, String parentClassification, String name, String keyWord, String imgPath, Boolean isRelevance, Boolean isDisplay, Boolean isRecommend, String desc) throws LJCBusinessException {
        return goodsService.addClassification(sort, parentClassification, name, keyWord, imgPath, isRelevance, isDisplay, isRecommend, desc);
    }

    @PostMapping("/deleteGoodsClassification")
    @ApiOperation(value = "删除商品分类")
    @ApiImplicitParam(name = "classificationId", value = "分类编号", required = true, dataType = "Long")
    public Map deleteGoodsClassification(Long classificationId) throws LJCBusinessException {
        return goodsService.deleteGoodsClassification(classificationId);
    }

    @PostMapping("/addLabelGroup")
    @ApiOperation(value = "添加标签组")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "labelGroup", value = "标签组对象"),
            @ApiImplicitParam(name = "labelGroupName", value = "标签组名称", required = true, dataType = "String"),
            @ApiImplicitParam(name = "labelGroupStatus", value = "是否启用", required = true, dataType = "Boolean"),
            @ApiImplicitParam(name = "labelName", value = "标签名(数组)", required = true, dataType = "String")
    })
    public Map addLabelGroup(@RequestBody Map<String, Object> map) throws LJCBusinessException {
        return goodsService.addLabelGroup(map);
    }

    @PostMapping("/findLabelGroup")
    @ApiOperation(value = "查询自定义标签组")
    public Map findLabelGroup() {
        return goodsService.findLabelGroup();
    }

    @PostMapping("/realDeleteGoods")
    @ApiOperation(value = "彻底删除商品")
    @ApiImplicitParam(name = "goodsId", value = "商品编号(数组)", required = true, dataType = "Long")
    public Map realDeleteGoods(@RequestBody Map<String, Object> map) {
        return goodsService.realDeleteGoods(map);
    }

    @PostMapping("/recoverGoods")
    @ApiOperation(value = "还原商品")
    @ApiImplicitParam(name = "goodsId", value = "商品编号(数组)", dataType = "Long")
    public Map recoverGoods(@RequestBody Map<String, Object> map) {
        return goodsService.recoverGoods(map);
    }

    @PostMapping("/selectClassification")
    @ApiOperation(value = "搜索分类")
    @ApiImplicitParam(name = "nameOrKeyword", value = "分类名或关键词", dataType = "String")
    public Map selectClassification(String nameOrKeyword) {
        return goodsService.selectClassification(nameOrKeyword);
    }

    @PostMapping("/getClassificationInfo")
    @ApiOperation(value = "获取分类信息(编辑分类时)")
    @ApiImplicitParam(name = "itemId", value = "分类编号", dataType = "Long")
    public Map getClassificationInfo(Long itemId) {
        return goodsService.getClassificationInfo(itemId);
    }

    @PostMapping("/editClassificationInfo")
    @ApiOperation(value = "编辑分类信息")
    @ApiImplicitParam(name = "item", value = "分类对象")
    public Map editClassificationInfo(@RequestBody Map<String, Object> map) throws LJCBusinessException {
        return goodsService.editClassificationInfo(map);
    }

    @PostMapping("/selectLabelGroup")
    @ApiOperation(value = "搜索标签组")
    @ApiImplicitParam(name = "name", value = "标签组名称", dataType = "String")
    public Map selectLabelGroup(String name) {
        return goodsService.selectLabelGroup(name);
    }

    @PostMapping("/activateLabelGroup")
    @ApiOperation(value = "启用标签组")
    @ApiImplicitParam(name = "labelGroupId", value = "标签组编号(数组)", dataType = "String")
    public Map activateLabelGroup(@RequestBody Map<String, Object> map) {
        return goodsService.activateOrDisabledLabelGroup(map, true);
    }

    @PostMapping("/disabledLabelGroup")
    @ApiOperation(value = "禁用标签组")
    @ApiImplicitParam(name = "labelGroupId", value = "标签组编号(数组)", dataType = "String")
    public Map disabledLabelGroup(@RequestBody Map<String, Object> map) {
        return goodsService.activateOrDisabledLabelGroup(map, false);
    }

    @PostMapping("/deleteLabelGroup")
    @ApiOperation(value = "删除标签组")
    @ApiImplicitParam(name = "labelGroupId", value = "标签组编号(数组)", dataType = "String")
    public Map deleteLabelGroup(@RequestBody Map<String, Object> map) {
        return goodsService.deleteLabelGroup(map);
    }

    @PostMapping("/editLabelGroup")
    @ApiOperation(value = "编辑标签组")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "labelName", value = "标签名称(数组)", dataType = "String"),
            @ApiImplicitParam(name = "labelGroupId", value = "标签组编号", dataType = "Long"),
            @ApiImplicitParam(name = "labelGroup", value = "标签组对象"),
            @ApiImplicitParam(name = "labelGroupName", value = "标签组名称", dataType = "String"),
            @ApiImplicitParam(name = "labelGroupStatus", value = "标签组状态", dataType = "Boolean")
    })
    public Map editLabelGroup(@RequestBody Map<String, Object> map) {
        return goodsService.editLabelGroup(map);
    }

    @PostMapping("/addGoodsGroup")
    @ApiOperation(value = "添加商品组")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "goodsGroup", value = "商品组对象"),
            @ApiImplicitParam(name = "goodsGroupName", value = "商品组名称", required = true, dataType = "String"),
            @ApiImplicitParam(name = "goodsGroupStatus", value = "是否启用", required = true, dataType = "Boolean"),
            @ApiImplicitParam(name = "goodsId", value = "组内商品编号(数组)", required = true, dataType = "String")
    })
    public Map addGoodsGroup(@RequestBody Map<String, Object> map) throws LJCBusinessException {
        return goodsService.addGoodsGroup(map);
    }

    @PostMapping("/selectGoodsGroup")
    @ApiOperation(value = "搜索商品组")
    @ApiImplicitParam(name = "goodsGroupName", value = "商品组名称", dataType = "String")
    public Map selectGoodsGroup(String goodsGroupName) {
        return goodsService.selectGoodsGroup(goodsGroupName);
    }

    @PostMapping("/activateGoodsGroup")
    @ApiOperation(value = "启用商品组")
    @ApiImplicitParam(name = "goodsGroupId", value = "商品组编号(数组)", dataType = "String")
    public Map activateGoodsGroup(@RequestBody Map<String, Object> map) {
        return goodsService.activateOrDisabledGoodsGroup(map, true);
    }

    @PostMapping("/disabledGoodsGroup")
    @ApiOperation(value = "禁用商品组")
    @ApiImplicitParam(name = "goodsGroupId", value = "商品组编号(数组)", dataType = "String")
    public Map disabledGoodsGroup(@RequestBody Map<String, Object> map) {
        return goodsService.activateOrDisabledGoodsGroup(map, false);
    }

    @PostMapping("/deleteGoodsGroup")
    @ApiOperation(value = "删除商品组")
    @ApiImplicitParam(name = "goodsGroupId", value = "商品组编号(数组)", dataType = "String")
    public Map deleteGoodsGroup(@RequestBody Map<String, Object> map) {
        return goodsService.deleteGoodsGroup(map);
    }

    @PostMapping("/editGoodsGroup")
    @ApiOperation(value = "编辑商品组")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "goodsId", value = "商品编号(数组)", dataType = "String"),
            @ApiImplicitParam(name = "goodsGroupId", value = "商品组编号", dataType = "Long"),
            @ApiImplicitParam(name = "goodsGroup", value = "商品组对象"),
            @ApiImplicitParam(name = "goodsGroupName", value = "商品组名称", dataType = "String"),
            @ApiImplicitParam(name = "goodsGroupStatus", value = "商品组状态", dataType = "Boolean")
    })
    public Map editGoodsGroup(@RequestBody Map<String, Object> map) {
        return goodsService.editGoodsGroup(map);
    }
}
